<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Gallery/classes/PhpFox_ComponentBattleLeader.class.php, $Author:  $ */



/** Component for showing battle leaders list
 *
 * @version $Id: PhpFox_ComponentBattleLeader.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 * @package module.gallery
 */
class PhpFox_Mod_Gallery_ComponentBattleLeader extends BaseComponent
{
    function process()
    {
        $oGalleryItem = $this->_oModule->getItem('Gallery');
        /* @var $oGalleryItem PhpFox_Mod_Gallery_ItemGallery */
        $oGalleryService = $this->_oModule->getService('Gallery');
        /* @var $oGalleryService PhpFox_Mod_Gallery_ServiceGallery */
        $oSecurityService = App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
        App::loadClass('Filter');
        $oReq = &App::getRequest();
        $oTpl = $this->_oModule->getTemplate();
        $aOut = array();

        $oSecurityService->checkPerm('gallery.vote', array('read_only', 'full'));
        $oSecurityService->checkAccess('battle');
    	$aCategories = array();
        $aCategories[''] = App::format('option.select');
		foreach (App::getOptions('image_cat') as $sCategoryId => $sCategoryText)
        {
            $aCategories[$sCategoryId] = $sCategoryText;
        }
        $aCond = array
        (
        	'category' => array
        	(
        		'value'  => '=',
        		'select' => $aCategories,
        	),
        );
        $oFilter = &new Filter('battle', $aCond);
        $aCond = array();
        foreach ($oFilter->aConditions as $sCond)
        {
            $aCond[] = $sCond;
        }
        $aCond['allow'] = '= ""';
        $aCond['who_view'] = '= ""';
        $aCond['faceoff']  = '<> 0';

        $aJoin = array();
		$aJoin[] = " ". App::getT('user') ." AS u ON(ma.user_id = u.id) ";

        list($aItems, $iCnt) = $oGalleryItem->getList($aCond, 1, App::getParam('public.battle_leaders'), 'ma.faceoff DESC, ma.view ASC', '', '', 'ma.id, ma.text, ma.faceoff, ma.view, u.user', $aJoin);

        $oTpl->assign(array(
        	'aFilter'     => $oFilter->aHtml,
        	'aItems'      => $aItems,
            'sGImageUrl'  => App::getParam('gallery.pic.url'),
        	'sFilterName' => 'battle',
        	'iTopCnt'     => App::getParam('public.battle_leaders'),
        ));
        $aOut['main']   = $oTpl->fetch('BattleLeader.html');
        $aOut['filter'] = $oTpl->fetch('GroupFilter.html');
        return $aOut;
    }
}
?>